﻿using Furion;
using Furion.DynamicApiController;
using GWB.Application.Common;
using GWB.Application.System.MenuManage.Dtos;
using GWB.Application.System.MenuManage.MenuService;
using GWB.Core.Enum;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace GWB.Application.System.MenuManage
{
    /// <summary>
    /// 菜单管理
    /// </summary>
    [ApiDescriptionSettings("系统管理", Tag = "菜单管理", SplitCamelCase = false)]
    public class MenuAppService:IDynamicApiController
    {
        /// <summary>
        ///新增
        /// </summary>
        /// <param name="inputDto"></param>
        /// <returns></returns>
        [Authorization(Name = "新增菜单", Code = AuthCode.Add)]
        public async Task<MenuOutDto> Add(MenuCreateOrUpdateInputDto inputDto) 
        {
            return await App.GetService<IMenuService>().Add(inputDto);
        }
        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="inputDto"></param>
        /// <returns></returns>
        [Authorization(Name = "修改菜单", Code = AuthCode.Update)]
        public async Task<bool> Update(MenuCreateOrUpdateInputDto inputDto)
        {
            return await App.GetService<IMenuService>().Update(inputDto);
        }

        /// <summary>
        /// 删除菜单
        /// </summary>
        /// <param name="ids"></param>
        /// <returns></returns>
        [Authorization(Name = "删除菜单", Code = AuthCode.Delete)]
        public async Task<bool> Delete(List<long> ids)
        {
            return await App.GetService<IMenuService>().Delete(ids);
        }


        /// <summary>
        ///查询菜单（递归）
        /// </summary>
        /// <returns></returns>
        [Authorization(Name = "查询菜单", Code = AuthCode.Page)]
        public async Task<List<MenuOutDto>> GetMenuList() 
        {
            return await App.GetService<IMenuService>().GetMenuList(); 
        }

        /// <summary>
        /// 获取开放的方法的分类
        /// </summary>
        /// <returns></returns>
        [Authorization(Name = "查询开放方法分类", Code = AuthCode.None)]
        public List<string> GetActionClassList() 
        {
            return  App.GetService<IMenuService>().GetActionClassList();
        }

        /// <summary>
        /// 获取分类下面的开放方法
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [Authorization(Name = "查询开放方法", Code = AuthCode.None)]
        public async Task<List<ActionOutDto>> QueryActionList(List<string> inputDto) 
        {
            return await App.GetService<IMenuService>().QueryActionList(inputDto);
        }

        /// <summary>
        /// 编辑菜单的Action
        /// </summary>
        /// <returns></returns>
        [Authorization(Name = "编辑菜单的Action", Code = AuthCode.None)]
        public async Task<bool> EditMenuBindingAction(MenuBindingActionEditInputDto inputDto)
        {
            return await App.GetService<IMenuService>().EditMenuBindingAction(inputDto);
        }

        /// <summary>
        /// 获取菜单绑定的Action
        /// </summary>
        /// <param name="menuId"></param>
        /// <returns></returns>
        [Authorization(Name = "获取菜单绑定的Action", Code = AuthCode.None)]
        public async Task<MenuBindingActionOutDto> GetMenuBindingAction(long menuId)
        {
            return await App.GetService<IMenuService>().GetMenuBindingAction(menuId);

        }

        /// <summary>
        /// 获取绑定菜单的Action
        /// </summary>
        /// <param name="menuIds"></param>
        /// <returns></returns>
        [Authorization(Name = "批量获取菜单绑定的Action", Code = AuthCode.None)]
        [HttpPost]
        public async Task<List<MenuBindingActionOutDto>> GetMenuBindingAction(List<long> menuIds)
        {
            return await App.GetService<IMenuService>().GetMenuBindingAction(menuIds);
        }
    }
}
